from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-30 14:02:11.567688
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 30, Mar, 2022
Time: 14:02:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.7514
Nobs: 611.000 HQIC: -49.1488
Log likelihood: 7379.49 FPE: 3.50835e-22
AIC: -49.4018 Det(Omega_mle): 3.03144e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.342713 0.065938 5.197 0.000
L1.Burgenland 0.106523 0.040339 2.641 0.008
L1.Kärnten -0.110826 0.021098 -5.253 0.000
L1.Niederösterreich 0.194653 0.084311 2.309 0.021
L1.Oberösterreich 0.118435 0.083060 1.426 0.154
L1.Salzburg 0.258912 0.042769 6.054 0.000
L1.Steiermark 0.040208 0.056461 0.712 0.476
L1.Tirol 0.105512 0.045546 2.317 0.021
L1.Vorarlberg -0.066609 0.040241 -1.655 0.098
L1.Wien 0.017312 0.073992 0.234 0.815
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051248 0.141370 0.363 0.717
L1.Burgenland -0.037645 0.086485 -0.435 0.663
L1.Kärnten 0.041965 0.045233 0.928 0.354
L1.Niederösterreich -0.201759 0.180761 -1.116 0.264
L1.Oberösterreich 0.454830 0.178079 2.554 0.011
L1.Salzburg 0.282752 0.091696 3.084 0.002
L1.Steiermark 0.113033 0.121050 0.934 0.350
L1.Tirol 0.306598 0.097651 3.140 0.002
L1.Vorarlberg 0.026780 0.086275 0.310 0.756
L1.Wien -0.029105 0.158637 -0.183 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195876 0.033668 5.818 0.000
L1.Burgenland 0.088781 0.020597 4.310 0.000
L1.Kärnten -0.007254 0.010773 -0.673 0.501
L1.Niederösterreich 0.243371 0.043050 5.653 0.000
L1.Oberösterreich 0.160286 0.042411 3.779 0.000
L1.Salzburg 0.040019 0.021838 1.833 0.067
L1.Steiermark 0.027400 0.028829 0.950 0.342
L1.Tirol 0.082929 0.023256 3.566 0.000
L1.Vorarlberg 0.054162 0.020547 2.636 0.008
L1.Wien 0.116362 0.037781 3.080 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115471 0.033712 3.425 0.001
L1.Burgenland 0.042683 0.020624 2.070 0.038
L1.Kärnten -0.013088 0.010787 -1.213 0.225
L1.Niederösterreich 0.173316 0.043106 4.021 0.000
L1.Oberösterreich 0.334975 0.042466 7.888 0.000
L1.Salzburg 0.099822 0.021867 4.565 0.000
L1.Steiermark 0.112745 0.028867 3.906 0.000
L1.Tirol 0.090860 0.023287 3.902 0.000
L1.Vorarlberg 0.060655 0.020574 2.948 0.003
L1.Wien -0.017856 0.037830 -0.472 0.637
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121719 0.063153 1.927 0.054
L1.Burgenland -0.045729 0.038635 -1.184 0.237
L1.Kärnten -0.045575 0.020206 -2.255 0.024
L1.Niederösterreich 0.138525 0.080750 1.715 0.086
L1.Oberösterreich 0.161858 0.079551 2.035 0.042
L1.Salzburg 0.284207 0.040963 6.938 0.000
L1.Steiermark 0.059008 0.054076 1.091 0.275
L1.Tirol 0.159986 0.043623 3.668 0.000
L1.Vorarlberg 0.097704 0.038541 2.535 0.011
L1.Wien 0.071038 0.070866 1.002 0.316
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.071231 0.049327 1.444 0.149
L1.Burgenland 0.025140 0.030177 0.833 0.405
L1.Kärnten 0.053008 0.015783 3.359 0.001
L1.Niederösterreich 0.192426 0.063072 3.051 0.002
L1.Oberösterreich 0.330843 0.062136 5.325 0.000
L1.Salzburg 0.035342 0.031995 1.105 0.269
L1.Steiermark 0.009533 0.042237 0.226 0.821
L1.Tirol 0.121558 0.034073 3.568 0.000
L1.Vorarlberg 0.066199 0.030104 2.199 0.028
L1.Wien 0.096272 0.055352 1.739 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169273 0.059443 2.848 0.004
L1.Burgenland 0.005797 0.036365 0.159 0.873
L1.Kärnten -0.066065 0.019019 -3.474 0.001
L1.Niederösterreich -0.105038 0.076006 -1.382 0.167
L1.Oberösterreich 0.206884 0.074878 2.763 0.006
L1.Salzburg 0.054496 0.038556 1.413 0.158
L1.Steiermark 0.247652 0.050899 4.866 0.000
L1.Tirol 0.502865 0.041060 12.247 0.000
L1.Vorarlberg 0.064314 0.036277 1.773 0.076
L1.Wien -0.077638 0.066704 -1.164 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156972 0.065937 2.381 0.017
L1.Burgenland -0.002431 0.040338 -0.060 0.952
L1.Kärnten 0.062478 0.021097 2.961 0.003
L1.Niederösterreich 0.169040 0.084309 2.005 0.045
L1.Oberösterreich -0.055678 0.083058 -0.670 0.503
L1.Salzburg 0.207749 0.042768 4.858 0.000
L1.Steiermark 0.139452 0.056459 2.470 0.014
L1.Tirol 0.058685 0.045545 1.288 0.198
L1.Vorarlberg 0.147062 0.040240 3.655 0.000
L1.Wien 0.119455 0.073990 1.614 0.106
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389272 0.038787 10.036 0.000
L1.Burgenland -0.004403 0.023728 -0.186 0.853
L1.Kärnten -0.020982 0.012410 -1.691 0.091
L1.Niederösterreich 0.202972 0.049594 4.093 0.000
L1.Oberösterreich 0.230914 0.048858 4.726 0.000
L1.Salzburg 0.036392 0.025158 1.447 0.148
L1.Steiermark -0.015768 0.033212 -0.475 0.635
L1.Tirol 0.089760 0.026792 3.350 0.001
L1.Vorarlberg 0.051135 0.023671 2.160 0.031
L1.Wien 0.043666 0.043524 1.003 0.316
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036818 0.109470 0.173209 0.139569 0.101826 0.081707 0.036448 0.210933
Kärnten 0.036818 1.000000 -0.026232 0.130992 0.049143 0.085206 0.443700 -0.066413 0.089681
Niederösterreich 0.109470 -0.026232 1.000000 0.314251 0.120912 0.274872 0.068091 0.155017 0.293163
Oberösterreich 0.173209 0.130992 0.314251 1.000000 0.213839 0.297353 0.167234 0.138703 0.239653
Salzburg 0.139569 0.049143 0.120912 0.213839 1.000000 0.124468 0.092963 0.106381 0.125035
Steiermark 0.101826 0.085206 0.274872 0.297353 0.124468 1.000000 0.135439 0.108929 0.036918
Tirol 0.081707 0.443700 0.068091 0.167234 0.092963 0.135439 1.000000 0.065581 0.151102
Vorarlberg 0.036448 -0.066413 0.155017 0.138703 0.106381 0.108929 0.065581 1.000000 -0.002997
Wien 0.210933 0.089681 0.293163 0.239653 0.125035 0.036918 0.151102 -0.002997 1.000000